<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>if指令</title>
    <style>
        .box1 {
            width: 300px;
            height: 300px;
            background-color: skyblue;
        }

        .box2 {
            width: 300px;
            height: 300px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div id="app">
        <div v-if="show" class="box1">

        </div>
        <button id="btn">点击显示/隐藏</button>

        <hr>
        <div v-show="show" class="box2">
            <h1>我是盒子1</h1>
        </div>
        <div v-show="!show" class="box2">
            <h1>我是盒子2</h1>
        </div>

        <div v-if="num >= 10? true: false" class="box2">

        </div>

        <hr>

        <div>
            <div v-if="login_status">
                <a href="./user.html">个人中心</a>
            </div>
            <div v-else>
                <a href="./login.html">登录页</a>
            </div>
        </div>

        <div id="big-box">

        </div>
        <button id="btn2">点击隐藏</button>
        <button id="btn3">点击添加</button>
    </div>
</body>
<script src=" https://cdn.jsdelivr.net/npm/vue@2.6.14">
</script>
<script>
    // 实例化Vue对象
    let app = new Vue({
        el: '#app',         // Vue对象在页面中的作用容器
        // 当前Vue对象设置的默认数据
        data: {
            show: false,
            num: 6,
            login_status: false
        }

    })

    let btn = document.getElementById('btn')

    // 当执行的语句要当成值来使用时，我们就需要使用匿名函数进行包裹
    btn.addEventListener('click', () => {
        app.show = !app.show
    })

    let h1Ele = document.createElement('h1')
    h1Ele.innerText = '小明好可爱'

    document.getElementById('big-box').appendChild(h1Ele)

    document.getElementById('btn2').onclick = () => {
        console.log(document.getElementById('big-box').children[0])
        document.getElementById('big-box').children[0].remove()
    }

    document.getElementById('btn3').onclick = () => {
        document.getElementById('big-box').appendChild(h1Ele)
    }
</script>

</html>